package com.ruoyi.fetv.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.fetv.domain.FetvSchool;

import com.ruoyi.fetv.mapper.FetvInformationMapper;
import com.ruoyi.fetv.mapper.FetvSchoolMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.fetv.domain.FetvInformation;
import com.ruoyi.fetv.service.IFetvInformationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资讯Controller
 *
 * @author zhengmingjie
 * @date 2023-02-27
 */
@RestController
@RequestMapping("/fetv/information")
@CrossOrigin
public class FetvInformationController extends BaseController {
    @Resource
    private IFetvInformationService fetvInformationService;

    @Resource
    private FetvInformationMapper fetvInformationMapper;

    /**
     * 查询资讯列表
     *
     * @param fetvInformation
     * @return
     */
    @Anonymous
    //@PreAuthorize("@ss.hasPermi('system:information:list')")
    @GetMapping("/list")
    public TableDataInfo list(FetvInformation fetvInformation) {
        startPage();
        List<FetvInformation> list = fetvInformationService.selectFetvInformationList(fetvInformation);
        return getDataTable(list);
    }

    /**
     * 导出资讯列表
     *
     * @param response
     * @param fetvInformation
     */
    @Anonymous
    //@PreAuthorize("@ss.hasPermi('system:information:export')")
    @Log(title = "资讯", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FetvInformation fetvInformation) {
        List<FetvInformation> list = fetvInformationService.selectFetvInformationList(fetvInformation);
        ExcelUtil<FetvInformation> util = new ExcelUtil<FetvInformation>(FetvInformation.class);
        util.exportExcel(response, list, "资讯数据");
    }

    /**
     * 获取资讯详细信息
     *
     * @param informationId
     * @return
     */
    @Anonymous
    //@PreAuthorize("@ss.hasPermi('system:information:query')")
    @GetMapping(value = "/{informationId}")
    public AjaxResult getInfo(@PathVariable("informationId") Integer informationId) {
        return success(fetvInformationService.selectFetvInformationByInformationId(informationId));
    }

    /**
     * 新增资讯
     *
     * @param fetvInformation
     * @return
     */
    @Anonymous
    //@PreAuthorize("@ss.hasPermi('system:information:add')")
    @Log(title = "资讯", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FetvInformation fetvInformation) {
        return toAjax(fetvInformationService.insertFetvInformation(fetvInformation));
    }

    /**
     * 修改资讯
     *
     * @param fetvInformation
     * @return
     */
    @Anonymous
    //@PreAuthorize("@ss.hasPermi('system:information:edit')")
    @Log(title = "资讯", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FetvInformation fetvInformation) {
        return toAjax(fetvInformationService.updateFetvInformation(fetvInformation));
    }

    /**
     * 根据ID修改资讯/审核状态
     *
     * @param informationId
     * @return
     */
    @Anonymous
    @GetMapping("/status")
    public AjaxResult editStatusById(@RequestParam Integer informationId, @RequestParam int status) {
        FetvInformation fetvInformation = fetvInformationMapper.selectFetvInformationByInformationId(informationId);
        fetvInformation.setStatus(status);
        return toAjax(fetvInformationService.updateFetvInformation(fetvInformation));
    }

    /**
     * 删除资讯/删除审核
     *
     * @param informationId
     * @return
     */
    @Anonymous
    //@PreAuthorize("@ss.hasPermi('system:information:remove')")
    @Log(title = "资讯", businessType = BusinessType.DELETE)
    @DeleteMapping("/{informationId}")
    public AjaxResult remove(@PathVariable Integer informationId) {
        return toAjax(fetvInformationService.deleteFetvInformationByInformationId(informationId));
    }

    /**
     * 查询审核表
     *
     * @param fetvInformation
     * @return
     */
    @Anonymous
    @GetMapping("/audit")
    public TableDataInfo auditList(FetvInformation fetvInformation) {
        startPage();
        List<FetvInformation> list = fetvInformationService.selectFetvInformationListVo(fetvInformation);
        return getDataTable(list);
    }


    /**
     * 根据ID修改资讯/审核状态
     *
     * @param informationId
     * @return
     */
    @Anonymous
    @GetMapping("/audit/examine")
    public AjaxResult editAuditById(@RequestParam Integer informationId, @RequestParam int examineStatus) {
        FetvInformation fetvInformation = fetvInformationMapper.selectFetvInformationByInformationId(informationId);
        fetvInformation.setExamineStatus(examineStatus);
        return toAjax(fetvInformationService.updateFetvInformation(fetvInformation));
    }


}
